package org.pku_uestc.hackathon.handler;

import org.pku_uestc.hackathon.CheckService;
import org.pku_uestc.hackathon.bean.ISensorHandler;
import org.pku_uestc.hackathon.sensor.SmartLight;
import org.pku_uestc.hackathon.utils.PrefUtils;

import android.content.Context;
import android.util.Log;

public class HighTempHandler implements ISensorHandler {

	private float threshold = 20;
	private Context context;
	
	public HighTempHandler(Context context){
		this.context = context;
	}
	
    @Override
    public boolean onAction() {
        // TODO Auto-generated method stub
    	Log.d(getClass().getName(), "action");
    	if(PrefUtils.getBooleanValue(context, CheckService.phone_pre
				+this.getType(), false)){
    		
    	}
    	
    	String s = PrefUtils.getStringValue(context, CheckService.light_pre
				+this.getType(), "");
    	if(!s.equals("")){
    		String[] ids = s.split(" ");
    		for(String id:ids)
    			SmartLight.getInstantces(Integer.parseInt(id)).action();
    	}
    	
        return false;
    }

    @Override
    public boolean check(Object... datas) {
        // TODO Auto-generated method stub
    	if(Float.parseFloat(datas[0].toString())>threshold){
    		onAction();
    	}
        return false;
    }

	@Override
	public int getType() {
		// TODO Auto-generated method stub
		return TYPE_HIGHTEMPHANDLER;
	}

	@Override
	public void changeThreshold(float threshold) {
		// TODO Auto-generated method stub
		this.threshold = threshold;
	}

}
